home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
ada
/
gwuada_9.zip
/
LIBR.C
< prev
next >
Wrap
C/C++ Source or Header
|
1993-07-27
|
43KB
|
1,446 lines
/*
* Copyright (C) 1985-1992 New York University
*
* This file is part of the Ada/Ed-C system. See the Ada/Ed README file for
* warranty (none) and distribution info and also the GNU General Public
* License for more details.
*/
/* libr - procedures for reading (in C format) ais and tre files*/
#include "hdr.h"
#include "vars.h"
#include "libhdr.h"
#include "ifile.h"
#include "dbxp.h"
#include "chapp.h"
#include "arithp.h"
#include "dclmapp.h"
#include "miscp.h"
#include "smiscp.h"
#include "setp.h"
#include "libfp.h"
#include "libp.h"
#include "librp.h"
static void getlitmap(IFILE *, Symbol);
static char *getmisc(IFILE *, Symbol, int);
static void getrepr(IFILE * , Symbol);
static void getnod(IFILE *, char *, Node, int);
static void getnval(IFILE *, Node);
static int *getuint(IFILE *, char *);
static void getovl(IFILE *, Symbol);
static void getsig(IFILE *, Symbol, int);
static void getudecl(IFILE *, int);
static Tuple add_tree_node(Tuple, Node);
static void retrieve_tree_nodes(IFILE *, int, Tuple);
extern IFILE *TREFILE, *AISFILE, *STUBFILE, *LIBFILE;
Declaredmap getdcl(IFILE *ifile) /*;getdcl*/
{
Declaredmap d;
char *id;
Symbol sym;
int n = 0, vis, i;
n = getnum(ifile, "dcl_is_map_defined");
if (n == 0) {
return (Declaredmap) 0;
}
n = getnum(ifile, "dcl-number-defined"); /* get item count */
d = dcl_new(n);
if (n == 0) return d;
for (i = 1; i <= n; i++) {
id = getstr(ifile, "sym-str");
sym = getsymref(ifile, "");
vis = getnum(ifile, "sym-vis");
dcl_put_vis(d, id, sym, vis);
}
return(d);
}
static void getlitmap(IFILE *ifile, Symbol sym) /*;gettlitmap*/
/* called for na_enum to input literal map.
* The literal map is a tuple, entries consisting of string followed
* by integer.
*/
{
Tuple tup;
int i, n;
n = getnum(ifile, "litmap-n");
tup = tup_new(n);
for (i = 1; i <= n; i+=2) {
tup[i] = getstr(ifile, "litmap-str");
tup[i+1] = (char *) getnum(ifile, "litmap-value");
}
OVERLOADS(sym) = (Set) tup;
}
static char *getmisc(IFILE *ifile, Symbol sym, int mval) /*;getmisc*/
{
/* read MISC information if present
* MISC is integer except for package, in which case it is a triple.
* The first two components are integers, the last is a tuple of
* symbols
*/
int nat, i, n;
Tuple tup, stup;
nat = NATURE(sym);
if ((nat == na_package || nat == na_package_spec)) {
if (mval) {
tup = tup_new(3);
tup[1] = (char *) getnum(ifile, "misc-package-1");
tup[2] = (char *) getnum(ifile, "misc-package-2");
n = getnum(ifile, "misc-package-tupsize");
stup = tup_new(n);
for (i = 1; i<= n; i++)
stup[i] = (char *) getsymref(ifile, "misc-package-symref");
tup[3] = (char *) stup;
return (char *) tup;
}
else {
getnum(ifile, "misc");
return (char *)MISC(sym);
}
}
else if ((nat == na_procedure || nat == na_function) && mval) {
tup = tup_new(2);
tup[1] = (char *) getnum(ifile, "misc-number");
tup[2] = (char *) getsymref(ifile, "misc-symref");
return (char *) tup;
}
else {
return (char *)getnum(ifile, "misc");
}
}
static void getrepr(IFILE * ifile, Symbol sym) /*;getrepr*/
{
/* read int representation information if present */
int repr_tag, i, n;
Tuple align_mod_tup,align_tup,repr_tup;
Tuple tup4;
repr_tag = getnum(ifile, "repr-type");
if (repr_tag != -1) {
if (repr_tag == TAG_RECORD) { /* record type */
repr_tup = tup_new(4);
repr_tup[1] = (char *) TAG_RECORD;
repr_tup[2] = (char *) getnum(ifile,"repr-rec-size");
align_mod_tup = tup_new(2);
align_mod_tup[1] = (char *) getnum(ifile,"repr-rec-mod");
n = getnum(ifile,"repr-align_tup_size");
align_tup = tup_new(0);
for (i=1; i<=n; i++) {
tup4 = tup_new(4);
tup4[1] = (char *) getsymref(ifile,"repr-rec-align-1");
tup4[2] = (char *) getnum(ifile,"repr-rec-align-2");
tup4[3] = (char *) getnum(ifile,"repr-rec-align-3");
tup4[4] = (char *) getnum(ifile,"repr-rec-align-4");
align_tup = tup_with(align_tup, (char *) tup4);
}
align_mod_tup[2] = (char *) align_tup;
repr_tup[4] = (char *) align_mod_tup;
REPR(sym) = repr_tup;
}
else if (repr_tag == TAG_ACCESS ||
repr_tag == TAG_TASK) { /* access or task type */
repr_tup = tup_new(3);
repr_tup[1] = (char *) repr_tag;
repr_tup[2] = (char *) getnum(ifile, "repr-size-2");
repr_tup[3] = (char *) getnodref(ifile, "repr-storage-size");
REPR(sym) = repr_tup;
}
else { /* non-record, non-access, non-task type */
n = getnum(ifile, "repr-tup-size");
repr_tup = tup_new(n);
repr_tup[1] = (char *) repr_tag;
for (i=2; i <= n; i++)
repr_tup[i] = (char *) getnum(ifile, "repr-info");
REPR(sym) = repr_tup;
}
}
}
static void getnod(IFILE *ifile, char *desc, Node node, int unum) /*;getnod*/
{
/*
* Read information for the node from a file (ifile)
* Since all the nodes in the tree all have the same N_UNIT value,
* the node can be read from the file in a more compact format.
* The N_UNIT of the node itself and of its children (N_AST1...) need not
* be read only their N_SEQ filed needs to be read. There is one
* complication of this scheme. OPT_NODE which is (seq=1, unit=0) will
* conflict with (seq=1,unit=X) of current unit. Therefore, in this case a
* sequence # of -1 will signify OPT_NODE.
*/
int i;
short nk, num1, num2, has_n_list;
Tuple ltup;
short fnum[24], fnums, fnumr=0;
/* copy standard info */
fnums = getnum(ifile, desc);
/*fread((char *) &fnums, sizeof(short), 1, ifile->fh_file);*/
fread((char *) fnum, sizeof(short), fnums, ifile->fh_file);
if (fnums == 0) {
chaos("getnod-fnums-zero");
}
fnumr = 0;
nk = fnum[fnumr++];
N_KIND(node) = nk;
N_SEQ(node) = fnum[fnumr++];
N_UNIT(node) = unum;
#ifdef DEBUG
if (trapns>0 && N_SEQ(node)== trapns && N_UNIT(node) == trapnu) trapn(node);
#endif
N_SPAN0(node) = N_SPAN1(node) = 0;
if (N_LIST_DEFINED(nk)) {
has_n_list = fnum[fnumr++];
ltup = (has_n_list) ? tup_new(has_n_list - 1) : (Tuple) 0;
}
else {
has_n_list = 0;
}
/* ast fields */
/* See comment above for description of compact format of node */
N_AST1(node) = N_AST2(node) = N_AST3(node) = N_AST4(node) = (Node)0;
if (N_AST1_DEFINED(nk)) {
num1 = fnum[fnumr++];
N_AST1(node) = (num1 == -1) ? OPT_NODE : getnodptr(num1, unum);
}
if (N_AST2_DEFINED(nk)) {
num1 = fnum[fnumr++];
N_AST2(node) = (num1 == -1) ? OPT_NODE : getnodptr(num1, unum);
}
if (N_AST3_DEFINED(nk)) {
num1 = fnum[fnumr++];
N_AST3(node) = (num1 == -1) ? OPT_NODE : getnodptr(num1, unum);
}
if (N_AST4_DEFINED(nk)) {
num1 = fnum[fnumr++];
N_AST4(node) = (num1 == -1) ? OPT_NODE : getnodptr(num1, unum);
}
if (N_UNQ_DEFINED(nk)) {
num1 = fnum[fnumr++];
num2 = fnum[fnumr++];
if (num1>0 || num2>0)
N_UNQ(node) = getsymptr(num1, num2);
}
if (N_TYPE_DEFINED(nk)) {
num1 = fnum[fnumr++];
num2 = fnum[fnumr++];
if (num1>0 || num2>0) {
N_TYPE(node) = getsymptr(num1, num2);
}
}
/* read out n_list if needed */
if (has_n_list > 0) {
for (i = 1; i<has_n_list; i++) {
ltup[i] = (char *) getnodref(ifile, "n-list-nodref");
}
if (ltup != (Tuple)0) {
N_LIST(node) = ltup;
}
}
if (N_VAL_DEFINED(nk))
getnval(ifile, node);
}
Node getnodref(IFILE *ifile, char *desc) /*;getnodref*/
{
Node node;
int seq, unit;
/*
* OPT_NODE is node in unit 0 with sequence 1, and needs
* no special handling here
*/
seq = getnum(ifile, "nref-seq");
unit = getnum(ifile, "nref-unt");
if (seq == 1 && unit == 0) {
return OPT_NODE;
}
else {
node = getnodptr(seq, unit);
#ifdef DEBUG
if (trapns>0 && trapns == seq && trapnu == unit) trapn(node);
#endif
}
return node;
}
static void getnval(IFILE *ifile, Node node) /*;getnval*/
{
/* read N_VAL field for node to AISFILE */
int nk, ck;
Const con;
char *nv;
Tuple tup;
int i, n, *rn, *rd;
double doub;
Symbolmap smap;
Symbol s1, s2;
nv = NULL; /* gs nov 1: added to avoid setting N_VAL incorrectly
at end of this routine */
swit